#!/bin/bash

SCRIPT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

REALM_CMAKE_SUBPLATFORM=${REALM_CMAKE_SUBPLATFORM:-$(uname -s)}
REALM_CMAKE_CONFIGURATION=${REALM_CMAKE_CONFIGURATION:-Debug}
REALM_CMAKE_INSTALL_TARGET=${REALM_CMAKE_INSTALL_TARGET:-install}
CMAKE_BINARY_DIR="$SCRIPT_DIRECTORY/cmake/$REALM_CMAKE_SUBPLATFORM"
CMAKE_INSTALL_PREFIX="$SCRIPT_DIRECTORY/build"

mkdir -p "$CMAKE_BINARY_DIR"
mkdir -p "$CMAKE_INSTALL_PREFIX"

cd $CMAKE_BINARY_DIR
cmake "$SCRIPT_DIRECTORY" -DCMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_PREFIX" -DCMAKE_BUILD_TYPE=$REALM_CMAKE_CONFIGURATION ${@:1}
cmake --build . --target $REALM_CMAKE_INSTALL_TARGET --config $REALM_CMAKE_CONFIGURATION
